package actions;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import beans.ModifAdresseBean;

import metier.IMetier;
import donnees.*;

public class ActionModifierAdresse extends UnicastRemoteObject implements IAction {
	private static final long serialVersionUID = 5378094902946793928L;

	public ActionModifierAdresse() throws RemoteException {
		super();
	}

	@Override
	public String execute(HttpServletRequest req) throws Exception{
		HttpSession theSession = req.getSession(true);
		ModifAdresseBean mab = new ModifAdresseBean(req.getParameter("num"),req.getParameter("rue"),req.getParameter("cp"),req.getParameter("ville"));
		req.setAttribute("modifadressebean", mab);
		boolean err = mab.valider();
		if(!err){
			req.setAttribute("ismodifying", "true");
			return "pageInfosClient.jsp";
		}else{
			IMetier metier=(IMetier)Naming.lookup("rmi://localhost:2000/ServeurMetier");
			Client c=((Client)theSession.getAttribute("leClient"));
			metier.modifierAdresseDuClient(c.getId(), req.getParameter("num"), req.getParameter("rue"), req.getParameter("cp"), req.getParameter("ville"));
			req.setAttribute("ismodifying", null);
			return "pageInfosClient.jsp";
		}

	}
}